package org.drools.devguide;

import org.drools.devguide.eshop.model.Item;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
import org.kie.api.cdi.KSession;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;

import javax.inject.Inject;

/**
 * Hello world!
 *
 */
public class App 
{
    @Inject
    @KSession
    KieSession kieSession;
    public  void go(){
        Item item=new Item("A",123.0,234.0);
        System.out.println("Item Category:"+item.getCategory());
        FactHandle factHandle=kieSession.insert(item);
        int fired=kieSession.fireAllRules();
        System.out.println("Number of Rules executed="+fired);
        System.out.println("Item Category:"+item.getCategory());
        System.out.println("update Item cost to 230.0");
        item.setCost(230.0);
        kieSession.update(factHandle,item);
        kieSession.fireAllRules();
        System.out.println("Item Category:"+item.getCategory());
    }

    public static void main( String[] args )
    {
        Weld weld=new Weld();
        WeldContainer weldContainer=weld.initialize();
        App app=weldContainer.instance().select(App.class).get();
        app.go();
        weld.shutdown();

    }
}
